import 'package:flutter/material.dart';
import 'package:portal_website/pages/common_header.dart';
import 'package:portal_website/tool/image_network.dart';

class DoublePage extends StatefulWidget {
  const DoublePage({super.key});

  @override
  State<DoublePage> createState() => _DoublePageState();
}

class _DoublePageState extends State<DoublePage>
    with SingleTickerProviderStateMixin {
  late TabController _tabController;

  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: 4, vsync: this);
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color(0xFFF5F9FF),
      body: SingleChildScrollView(
        child: Container(
          padding: const EdgeInsets.only(top: 10),

          // margin: const EdgeInsets.symmetric(horizontal: 10),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
// 面包屑导航
              const Padding(
                padding: EdgeInsets.symmetric(vertical: 15, horizontal: 10),
                child: Align(
                  alignment: Alignment.centerLeft,
                  child: Text(
                    '首页 > 双创政策',
                    style: TextStyle(
                      color: Color(0xFF666666),
                      fontSize: 14,
                    ),
                  ),
                ),
              ),
              PageTitle(
                title: "双创政策",
                subtitle: "汇聚河南省及濮阳市创新创业政策，助力企业发展",
              ),

// 双创政策介绍
              PolicyIntroSection(),

// 政策分类
              PolicySection(tabController: _tabController),

// 政策图片展示
              const GallerySection(),

// 页脚
              CommonFooter(
                links: [
                  {'name': '关于我们'},
                  {'name': '政策解读'},
                  {'name': '服务指南'},
                  {'name': '常见问题'},
                  {'name': '联系我们'},
                ],
                copyright: "© 2023 创新服务平台 版权所有",
                contactInfo:
                    "地址：河南省濮阳市XX区XX路XX号 | 服务热线：0393-1234567 | 邮箱：service@cxpt.com",
              )
            ],
          ),
        ),
      ),
    );
  }
}

// 导航链接组件
class NavLink extends StatelessWidget {
  final String text;

  const NavLink(this.text, {super.key});

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.symmetric(horizontal: 12.5),
      child: TextButton(
        onPressed: () {},
        style: TextButton.styleFrom(
          padding: EdgeInsets.zero,
          minimumSize: const Size(50, 30),
        ),
        child: Text(
          text,
          style: const TextStyle(
            color: Colors.white,
            fontSize: 16,
          ),
        ),
      ),
    );
  }
}

// 政策介绍部分
class PolicyIntroSection extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(8),
        boxShadow: [
          BoxShadow(
            color: Colors.black12,
            blurRadius: 3,
            spreadRadius: 1,
            offset: const Offset(0, 3),
          ),
        ],
      ),
      padding: const EdgeInsets.all(40),
      margin: const EdgeInsets.only(bottom: 40),
      child: Column(
        children: [
          if (MediaQuery.of(context).size.width > 768)
            Row(
              children: [
                Expanded(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: const [
                      Text(
                        '河南省双创政策概览',
                        style: TextStyle(
                          color: Color(0xFF1E5799),
                          fontSize: 24,
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                      SizedBox(
                        height: 20,
                      ),
                      Text(
                        '河南省高度重视创新创业工作，近年来出台了一系列支持政策，涵盖资金扶持、税收优惠、人才引进、平台建设等多个方面，为创新创业者提供了良好的政策环境和发展机遇。',
                        style: TextStyle(
                          color: Color(0xFF555555),
                          fontSize: 16,
                          height: 1.8,
                        ),
                      ),
                      SizedBox(
                        height: 20,
                      ),
                      Text(
                        '濮阳市作为河南省重要的区域中心城市，积极响应国家双创号召，结合本地产业特色，制定了多项配套政策措施，打造了多个创新创业孵化平台，为创业者提供全方位支持。',
                        style: TextStyle(
                          color: Color(0xFF555555),
                          fontSize: 16,
                          height: 1.8,
                        ),
                      ),
                      SizedBox(
                        height: 20,
                      ),
                      Text(
                        '本栏目汇集了最新的双创政策信息，帮助您及时了解政策动态，充分享受政策红利。',
                        style: TextStyle(
                          color: Color(0xFF555555),
                          fontSize: 16,
                          height: 1.8,
                        ),
                      ),
                    ],
                  ),
                ),
                const SizedBox(width: 40),
                ClipRRect(
                  borderRadius: BorderRadius.circular(8),
                  child: ImageNetwork(
                    '',
                    width: 500,
                    height: 300,
                    fit: BoxFit.cover,
                  ),
                ),
              ],
            ),
          if (MediaQuery.of(context).size.width <= 768)
            Column(
              children: [
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: const [
                    Text(
                      '河南省双创政策概览',
                      style: TextStyle(
                        color: Color(0xFF1E5799),
                        fontSize: 24,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                    SizedBox(
                      height: 20,
                    ),
                    Text(
                      '河南省高度重视创新创业工作，近年来出台了一系列支持政策，涵盖资金扶持、税收优惠、人才引进、平台建设等多个方面，为创新创业者提供了良好的政策环境和发展机遇。',
                      style: TextStyle(
                        color: Color(0xFF555555),
                        fontSize: 16,
                        height: 1.8,
                      ),
                    ),
                    SizedBox(
                      height: 20,
                    ),
                    Text(
                      '濮阳市作为河南省重要的区域中心城市，积极响应国家双创号召，结合本地产业特色，制定了多项配套政策措施，打造了多个创新创业孵化平台，为创业者提供全方位支持。',
                      style: TextStyle(
                        color: Color(0xFF555555),
                        fontSize: 16,
                        height: 1.8,
                      ),
                    ),
                    SizedBox(
                      height: 20,
                    ),
                    Text(
                      '本栏目汇集了最新的双创政策信息，帮助您及时了解政策动态，充分享受政策红利。',
                      style: TextStyle(
                        color: Color(0xFF555555),
                        fontSize: 16,
                        height: 1.8,
                      ),
                    ),
                  ],
                ),
                const SizedBox(height: 20),
                ClipRRect(
                  borderRadius: BorderRadius.circular(8),
                  child: ImageNetwork(
                    '',
                    width: double.infinity,
                    height: 300,
                    fit: BoxFit.cover,
                  ),
                ),
              ],
            ),
        ],
      ),
    );
  }
}

// 政策分类部分
class PolicySection extends StatefulWidget {
  final TabController tabController;

  const PolicySection({super.key, required this.tabController});

  @override
  State<PolicySection> createState() => _PolicySectionState();
}

class _PolicySectionState extends State<PolicySection> {
  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(8),
        boxShadow: [
          BoxShadow(
            color: Colors.black12,
            blurRadius: 3,
            spreadRadius: 1,
            offset: const Offset(0, 3),
          ),
        ],
      ),
      padding: const EdgeInsets.all(40),
      margin: const EdgeInsets.only(bottom: 40),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisSize: MainAxisSize.min,
        children: [
          const SectionTitle('政策分类'),
          const SizedBox(height: 30),

// 标签栏
          Container(
            decoration: const BoxDecoration(
              border: Border(
                bottom: BorderSide(color: Color(0xFFE0E9FF)),
              ),
            ),
            child: TabBar(
              controller: widget.tabController,
              labelColor: const Color(0xFF1E5799),
              unselectedLabelColor: const Color(0xFF666666),
              labelStyle: const TextStyle(
                fontSize: 16,
                fontWeight: FontWeight.bold,
              ),
              unselectedLabelStyle: const TextStyle(
                fontSize: 16,
              ),
              indicator: const UnderlineTabIndicator(
                borderSide: BorderSide(
                  color: Color(0xFF207CCA),
                  width: 3,
                ),
              ),
              tabs: const [
                Tab(text: '河南省政策'),
                Tab(text: '濮阳市政策'),
                Tab(text: '资金扶持'),
                Tab(text: '人才政策'),
              ],
              onTap: (index) {
// 切换标签时的回调
                setState(() {});
              },
            ),
          ),

// 标签内容
          Container(
            height: widget.tabController.index == 0 ? 540 : 350,
            child: TabBarView(
              controller: widget.tabController,
              physics: NeverScrollableScrollPhysics(),
              children: const [
                henanTab(),
                puyangTab(),
                jijinTab(),
                rencaiTab(),
              ],
            ),
          ),
        ],
      ),
    );
  }
}

// 河南省政策标签内容
class henanTab extends StatelessWidget {
  const henanTab({super.key});

  @override
  Widget build(BuildContext context) {
    return ListView(
      physics: NeverScrollableScrollPhysics(),
      shrinkWrap: true,
      children: const [
        PolicyItem(
          title: '河南省关于进一步促进大众创业万众创新若干政策措施',
          date: '2023-05-15',
          department: '河南省人民政府',
          content:
              '该政策从加大财政支持力度、优化创业环境、强化创业服务、加强创业培训等方面提出了30条具体措施，旨在进一步激发全社会创新创业活力。',
        ),
        PolicyItem(
          title: '河南省科技创新券实施管理办法',
          date: '2023-03-10',
          department: '河南省科技厅',
          content: '办法明确了科技创新券的发放对象、使用范围、申领流程等，支持科技型中小企业和创新创业团队购买创新服务。',
        ),
        PolicyItem(
          title: '河南省众创空间管理办法',
          date: '2022-12-05',
          department: '河南省科技厅',
          content: '规范众创空间的认定、管理和考核，推动众创空间高质量发展，为创业者提供更好的孵化服务。',
        ),
      ],
    );
  }
}

// 濮阳市政策标签内容
class puyangTab extends StatelessWidget {
  const puyangTab({super.key});

  @override
  Widget build(BuildContext context) {
    return ListView(
      children: const [
        PolicyItem(
          title: '濮阳市支持科技创新若干政策',
          date: '2023-04-20',
          department: '濮阳市人民政府',
          content: '从支持创新平台建设、促进科技成果转化、培育创新型企业等方面提出了具体支持措施。',
        ),
        PolicyItem(
          title: '濮阳市创业担保贷款实施办法',
          date: '2023-02-18',
          department: '濮阳市人社局',
          content: '明确了创业担保贷款的申请条件、额度、期限和贴息政策，支持各类群体创业。',
        ),
      ],
    );
  }
}

// 资金扶持标签内容
class jijinTab extends StatelessWidget {
  const jijinTab({super.key});

  @override
  Widget build(BuildContext context) {
    return ListView(
      children: const [
        PolicyItem(
          title: '河南省科技型中小企业技术创新资金管理办法',
          date: '2023-01-10',
          department: '河南省财政厅',
          content: '规范创新资金的使用和管理，支持科技型中小企业开展技术创新活动。',
        ),
        PolicyItem(
          title: '濮阳市科技创新专项资金管理办法',
          date: '2022-11-25',
          department: '濮阳市科技局',
          content: '明确了专项资金的扶持方向、申报条件和评审流程，支持本地科技创新项目。',
        ),
      ],
    );
  }
}

// 人才政策标签内容
class rencaiTab extends StatelessWidget {
  const rencaiTab({super.key});

  @override
  Widget build(BuildContext context) {
    return ListView(
      children: const [
        PolicyItem(
          title: '河南省高层次人才认定和支持办法',
          date: '2023-06-08',
          department: '河南省委组织部',
          content: '明确了高层次人才的分类标准、认定程序和配套支持政策，吸引海内外高端人才来豫创新创业。',
        ),
        PolicyItem(
          title: '濮阳市"龙都英才计划"实施办法',
          date: '2023-03-15',
          department: '濮阳市委人才办',
          content: '通过资金奖励、项目支持、住房保障等措施，吸引和培养各类优秀人才在濮阳创新创业。',
        ),
      ],
    );
  }
}

// 政策列表项组件
class PolicyItem extends StatelessWidget {
  final String title;
  final String date;
  final String department;
  final String content;

  const PolicyItem({
    super.key,
    required this.title,
    required this.date,
    required this.department,
    required this.content,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.all(20),
      margin: const EdgeInsets.only(bottom: 20),
      decoration: BoxDecoration(
        color: const Color(0xFFF9FBFF),
        borderRadius: BorderRadius.circular(8),
        border: const Border(
          left: BorderSide(
            color: Color(0xFF207CCA),
            width: 4,
          ),
        ),
        boxShadow: [
          BoxShadow(
            color: Colors.black12,
            blurRadius: 5,
            spreadRadius: 1,
            offset: const Offset(0, 5),
          ),
        ],
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            title,
            style: const TextStyle(
              color: Color(0xFF1E5799),
              fontSize: 18,
              fontWeight: FontWeight.bold,
            ),
          ),
          SizedBox(
            height: 10,
          ),
          Text(
            '发布日期：$date | 发布单位：$department',
            style: const TextStyle(
              color: Color(0xFF888888),
              fontSize: 14,
            ),
          ),
          SizedBox(
            height: 10,
          ),
          Text(
            content,
            style: const TextStyle(
              color: Color(0xFF555555),
              fontSize: 15,
              height: 1.6,
            ),
          ),
          SizedBox(
            height: 10,
          ),
          TextButton(
            onPressed: () {},
            style: TextButton.styleFrom(
              padding: EdgeInsets.zero,
              minimumSize: const Size(50, 30),
            ),
            child: const Text(
              '查看详情 →',
              style: TextStyle(
                color: Color(0xFF207CCA),
                fontWeight: FontWeight.bold,
                fontSize: 14,
              ),
            ),
          ),
        ],
      ),
    );
  }
}

// 政策图片展示部分
class GallerySection extends StatelessWidget {
  const GallerySection({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(8),
        boxShadow: [
          BoxShadow(
            color: Colors.black12,
            blurRadius: 3,
            spreadRadius: 1,
            offset: const Offset(0, 3),
          ),
        ],
      ),
      padding: const EdgeInsets.all(40),
      margin: const EdgeInsets.only(bottom: 40),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          const SectionTitle('双创风采'),
          const Padding(
            padding: EdgeInsets.only(bottom: 30),
            child: Text('河南省及濮阳市双创工作成果展示'),
          ),

// 图片网格
          GridView.count(
            shrinkWrap: true,
            physics: const NeverScrollableScrollPhysics(),
            crossAxisCount: MediaQuery.of(context).size.width > 768 ? 3 : 1,
            crossAxisSpacing: 20,
            mainAxisSpacing: 20,
            childAspectRatio: 400 / 300,
            children: const [
              GalleryItem(
                imageUrl: '',
                title: '河南省双创活动周',
                description: '2023年河南省大众创业万众创新活动周主会场',
              ),
              GalleryItem(
                imageUrl: '',
                title: '濮阳市创业孵化基地',
                description: '为创业者提供办公场地、创业指导和政策支持',
              ),
              GalleryItem(
                imageUrl: '',
                title: '河南省创新创业大赛',
                description: '发掘和培育优秀创新创业项目',
              ),
            ],
          ),
        ],
      ),
    );
  }
}

// 图片展示项组件
class GalleryItem extends StatelessWidget {
  final String imageUrl;
  final String title;
  final String description;

  const GalleryItem({
    super.key,
    required this.imageUrl,
    required this.title,
    required this.description,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(8),
        boxShadow: [
          BoxShadow(
            color: Colors.black12,
            blurRadius: 5,
            spreadRadius: 1,
            offset: const Offset(0, 5),
          ),
        ],
        // overflow: Clip.none,
      ),
      child: Stack(
        children: [
          ImageNetwork(
            imageUrl,
            width: double.infinity,
            height: double.infinity,
            fit: BoxFit.cover,
          ),
          Positioned(
            bottom: 0,
            left: 0,
            right: 0,
            child: Container(
              padding: const EdgeInsets.all(15),
              color: const Color.fromRGBO(30, 87, 153, 0.8),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    title,
                    style: const TextStyle(
                      color: Colors.white,
                      fontSize: 16,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                  SizedBox(
                    height: 5,
                  ),
                  Text(
                    description,
                    style: const TextStyle(
                      color: Colors.white,
                      fontSize: 14,
                      // opacity: 0.9,
                    ),
                  ),
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }
}

// 页脚链接组件
class FooterLink extends StatelessWidget {
  final String text;

  const FooterLink(this.text, {super.key});

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.symmetric(horizontal: 20),
      child: TextButton(
        onPressed: () {},
        style: TextButton.styleFrom(
          padding: EdgeInsets.zero,
          minimumSize: const Size(50, 30),
        ),
        child: Text(
          text,
          style: const TextStyle(
            color: Color(0xFFA8B2D1),
          ),
        ),
      ),
    );
  }
}

// 章节标题组件
class SectionTitle extends StatelessWidget {
  final String text;

  const SectionTitle(this.text, {super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.only(
        bottom: 15,
      ),
      margin: EdgeInsets.only(bottom: 30),
      decoration: const BoxDecoration(
        border: Border(
          bottom: BorderSide(
            color: Color(0xFFF0F0F0),
            width: 2,
          ),
        ),
      ),
      child: Stack(
        children: [
          Text(
            text,
            style: const TextStyle(
              color: Color(0xFF1E5799),
              fontSize: 24,
              fontWeight: FontWeight.bold,
            ),
          ),
          Positioned(
            bottom: -2,
            left: 0,
            width: 80,
            height: 2,
            child: Container(
              color: const Color(0xFF207CCA),
            ),
          ),
        ],
      ),
    );
  }
}
